<!DOCTYPE html>
<html>
<head>
    <title>订单列表</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link rel="stylesheet" href="../lib/weui.min.css">
    <link rel="stylesheet" href="../css/jquery-weui.css">
    <link rel="stylesheet" href="../css/base.css?12345">
    <link rel="stylesheet" href="../css/detailList.css?1245">
</head>
<body>
<div class="xyg-detail weui-flex">
    <div class="weui-flex__item ">
        <div class="placeholder" id="statusall">全部</div>
    </div>
    <div class="weui-flex__item ">
        <div class="placeholder" id="statusone">待支付</div>
    </div>
    <div class="weui-flex__item ">
        <div class="placeholder" id="statustwo">待发货</div>
    </div>
    <div class="weui-flex__item ">
        <div class="placeholder" id="statusthree">待收货</div>
    </div>
    <!--<div class="weui-flex__item <#if status=='5'>active</#if>"><div class="placeholder" id="statusfive">已取消</div></div>-->
</div>
<div class="xyg-cart">
    <div class="xyg-cart-show">

    </div>
</div>
<script type="text/x-handlebars-template" id="order-list-temp">
    <div class="xyg-cart-list">
        <div class="xyg-cart-list-head">
            <div class="xyg-cart-list-head-title">自营</div>
            <div class="xyg-cart-list-head-time">{{createTime}}</div>
        </div>

        {{#each orderItemList}}
        <div class="weui-cell weui-cell_swiped">
            <div class="xyg-cart-list-content weui-cell__bd" onclick="">
                <div class="xyg-cart-list-content-pic">
                    <img style="height: 80px" src="{{getImgArrFirst image}}">
                </div>
                <div class="xyg-cart-list-content-text">
                    <div class="xyg-cart-list-content-text-title">{{title}}</div>
                    <div class="xyg-cart-list-content-text-proper">{{paramData}}</div>
                    <div class="xyg-cart-list-content-text-pricenum">
                        <div class="xyg-cart-list-content-text-price">
                            ￥{{prePrice}}<num>X {{num}}</num>
                        </div>
                    </div>
                </div>
                <div style="width: 100%;clear: both;"></div>
            </div>
        </div>
        {{/each}}
    </div>
</script>
</body>
<script src="../lib/jquery-2.1.4.js"></script>
<script src="../js/jquery-weui.js"></script>
<script src="../js/swiper.min.js"></script>
<script src="../fonts/iconfont.js"></script>
<script src="../lib/fastclick.js"></script>
<script src="../lib/handlebars.min.js"></script>
<script src="../js/config.js"></script>
<!--<script src="../js/base.js"></script>-->
<script>
    $(function () {
        FastClick.attach(document.body);
    });
</script>
<script type="text/javascript">
    var memberId = getQueryString("memberId");
    var status = getQueryString("status");
    var pageStart = 0;
    var num = 10;
    var loading = false;  //状态标记

    if (!status){
        $("#statusall").parent().addClass("active");
    }else if(status == "1") {
        $("#statusone").parent().addClass("active");
    }else if(status == "2") {
        $("#statustwo").parent().addClass("active");
    }else if(status == "3") {
        $("#statusthree").parent().addClass("active");
    }

    sendPost();
    $(document).ready(function (e) {
        initPage();
        $(document.body).infinite().on("infinite", function () {
            if (loading) return;
            loading = true;
            sendPost();
        });
    });
    function sendPost() {
        $("#showContent").hide();
        pageStart++;
        $.get(baseURL + "api/order/page", {
            size: num,
            current: pageStart,
            status: status,
            memberId: memberId
        }, function (resultInfo) {
            if (resultInfo.data != null && resultInfo.data.length > 0) {
                for (var j = 0; j < resultInfo.data.length; j++) {
                    var orderInfo = resultInfo.data[j];
                    // 使用
                    var orderTemp = $('#order-list-temp').html();
                    var hanOrder = Handlebars.compile(orderTemp);
                    $(".xyg-cart .xyg-cart-show").append(hanOrder(orderInfo));
                    loading = false;
                    if (!resultInfo.hasNextPage) {
                        $(document.body).destroyInfinite();
                        $(".xyg-product-list_loadmore").hide();
                    }
                }
            } else {
                $(document.body).destroyInfinite();
                $(".xyg-product-list_loadmore").hide();
                $("#showContent").show();
            }

        }, "json");
    }

    $("#statusall").on("click", function () {
        $(".xyg-cart .xyg-cart-show").html("");
        $(".weui-flex__item").removeClass("active");
        $(this).parent().addClass("active");
        pageStart = 0;
        status = "";
        initPage();
        sendPost();
    });
    $("#statusone").on("click", function () {
        $(".xyg-cart .xyg-cart-show").html("");
        $(".weui-flex__item").removeClass("active");
        $(this).parent().addClass("active");
        pageStart = 0;
        status = "1";
        initPage();
        sendPost();
    });
    $("#statustwo").on("click", function () {
        $(".xyg-cart .xyg-cart-show").html("");
        $(".weui-flex__item").removeClass("active");
        $(this).parent().addClass("active");
        pageStart = 0;
        status = "2";
        initPage();
        sendPost();
    });
    $("#statusthree").on("click", function () {
        $(".xyg-cart .xyg-cart-show").html("");
        $(".weui-flex__item").removeClass("active");
        $(this).parent().addClass("active");
        pageStart = 0;
        status = "3";
        initPage();
        sendPost();
    })
    $("#statusfive").on("click", function () {
        $(".xyg-cart .xyg-cart-show").html("");
        $(".weui-flex__item").removeClass("active");
        $(this).parent().addClass("active");
        pageStart = 0;
        status = "5";
        initPage();
        sendPost();
    });

    function initPage() {
        $(document.body).infinite();
        $(".xyg-product-list_loadmore").show();
    }

    function goDesc(orderId, memberId) {
        window.location.href = "/phone/detail?memberId=" + memberId + "&orderId=" + orderId;
    }
    function goDescShow(orderId, memberId) {
        window.location.href = "/phone/detailShow?memberId=" + memberId + "&orderId=" + orderId;
    }
    function goDelDesc(orderId, memberId) {
        window.location.href = "/phone/detailDelShow?memberId=" + memberId + "&orderId=" + orderId;
    }

    function cancelOrder(orderId, memberId) {
        $.confirm("您确定要删除该订单吗？", "删除提示", function () {
            var param = {orderId: orderId, memberId: memberId}
            $.showLoading("正在提交中");
            $.post("/phone/order/cancel", param, function (result) {
                if (1 == result.returnInfo.state) {
                    $.hideLoading();
                    window.location.href = "/phone/detailList?memberId=" + memberId + "&status=" + status;
                    /* window.location.href="/phone/detailList?memberId="+memberId+"&status=2";*/
                } else {
                    $.hideLoading();
                    $.toast(result.returnInfo.errorMsg, "text");
                }
            }, "json");
        }, function () {
            //取消操作
        });

    }

    Handlebars.registerHelper("getImgArrFirst",function(str) {
        if(str==null || str=="") {
            return str;
        }
        var imageArr = str.split(",");
        if(imageArr != null && imageArr.length > 0){
            return imageArr[0];
        }
        return "";
    });
</script>

</html>
</html>

